<?php
/**
 * CDate class file.
 * 
 * @author Lucas Vasconcelos <contato@lucasvasconcelos.com>
 * @copyright Copyright(c) 2010 Lucas Vasconcelos
 * @license BSD License http://www.lucasvasconcelos.com/yap/license
 * @link http://www.lucasvasconcelos.com/yap/
 * @version $Id$
 * @package yap.helpers
 */

/**
 * CDate class.
 * 
 * @author Lucas Vasconcelos <contato@lucasvasconcelos.com>
 * @version 1.0 $Revision$
 * @package yap.helpers
 */
class CDate
{
	/**
	 * Converts from DB format (y-m-d) to given format.
	 * @param string date to be converted.
	 * @param string format
	 * @return string
	 */
	public static function dbToFormat($date,$format)
	{
		if($date=='') return null;
		list($y,$m,$d)=explode('-',$date);
		return date('d/m/Y',mktime(0,0,0,$m,$d,$y));
	}

	/**
	 * Converts from given format to DB format (y-m-d).
	 * @param string date to be converted.
	 * @param string format
	 * @return string
	 */
	public static function toDbFormat($date,$format)
	{
		if($date=='') return null;
		list($d,$m,$y)=explode('/',$date);
		return date('Y-m-d',mktime(0,0,0,$m,$d,$y));
	}
}